package com.cee.controller;

import com.cee.common.result.Result;
import com.cee.dto.ExamDTO;
import com.cee.dto.OneTypeDTO;
import com.cee.model.Exam;
import com.cee.model.OneType;
import com.cee.service.ExamService;
import com.cee.service.OneTypeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private ExamService examService;

    @PostMapping ("/list")
    public Result getList(@RequestBody ExamDTO examDTO){
        PageInfo pageInfo = examDTO.getPageInfo();
        Page<OneType> page = PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());

        examService.getExamList(examDTO);
        return Result.ok(new PageInfo<>(page));
    }

    @PostMapping ("/add")
    public Result addExam(@RequestBody ExamDTO examDTO){
        examService.saveExam(examDTO);
        return Result.ok();
    }


    @GetMapping ("/delete")
    public Result deleteExam(Integer id){

        examService.deleteExamById(id);
        return Result.ok();
    }


    @GetMapping ("/detail")
    public Result getExamById(Integer id){

        ExamDTO examDTO = examService.getExamById(id);
        return Result.ok(examDTO);
    }




}
